import * as BABYLON from 'babylonjs';

/*
  使用bbl渲染
  点集合 线集 面集 法线
  几何算法
  渲染
*/
/*
  四边形
  随机点集
  算法调整点集合
  每一步显示
*/

/*
  [x] 测试bbl
  自建网格
*/
export function hw8 () {
  testBabylon();
}

function testBabylon () {
  const canvas = document.getElementById('canvas') as HTMLCanvasElement;
  const engine = new BABYLON.Engine(canvas, true);
  
  const scene = new BABYLON.Scene(engine);
  const camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 5, -10), scene);
  camera.setTarget(BABYLON.Vector3.Zero());
  camera.attachControl(canvas, false);
  const light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0, 1, 0), scene);
  const sphere = BABYLON.MeshBuilder.CreateSphere('sphere', { segments: 16, diameter: 2 }, scene);
  sphere.position.y = 1;
  BABYLON.MeshBuilder.CreateGround('ground', { width: 6, height: 6, subdivisions: 2 }, scene);

    engine.runRenderLoop(() => {
      scene.render();
    });
    window.addEventListener('resize', () => {
      engine.resize();
    });
}